home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / pibt3sp2.arc / PIBDIR.PAS < prev    next >
Pascal/Delphi Source File  |  1985-10-04  |  41KB  |  827 lines

  1. (*----------------------------------------------------------------------*)
  2. (*        PIBDIR.PAS --- MSDOS Directory Routines for Turbo Pascal      *)
  3. (*----------------------------------------------------------------------*)
  4. (*                                                                      *)
  5. (*  Author:  Philip R. Burns                                            *)
  6. (*  Version: 1.0  (January,1985)                                        *)
  7. (*           2.0  (June,1985)                                           *)
  8. (*  Systems: For MS-DOS on IBM PCs and close compatibles only.          *)
  9. (*           Note:  I have checked these on Zenith 151s under           *)
  10. (*                  MSDOS 2.1 and IBM PCs under PCDOS 2.0.              *)
  11. (*                                                                      *)
  12. (*  Needs:   Global types from GLOBTYPE.PAS.                            *)
  13. (*                                                                      *)
  14. (*  History: Original with me.                                          *)
  15. (*                                                                      *)
  16. (*           Suggestions for improvements or corrections are welcome.   *)
  17. (*           Please leave messages on Gene Plantz's BBS (312) 882 4145  *)
  18. (*           or Ron Fox's BBS (312) 940 6496.                           *)
  19. (*                                                                      *)
  20. (*           IF you use this code in your own programs, please be nice  *)
  21. (*           and give proper credit.                                    *)
  22. (*                                                                      *)
  23. (*----------------------------------------------------------------------*)
  24. (*                                                                      *)
  25. (*  Routines:                                                           *)
  26. (*                                                                      *)
  27. (*      Convert_AsciiZ_To_String                                        *)
  28. (*      Convert_String_To_AsciiZ                                        *)
  29. (*      Dir_Get_Default_Drive                                           *)
  30. (*      Dir_Set_Default_Drive                                           *)
  31. (*      Dir_Get_Current_Path                                            *)
  32. (*      Dir_Set_Current_Path                                            *)
  33. (*      Dir_Set_Disk_Transfer_Address                                   *)
  34. (*      Dir_Delete_File                                                 *)
  35. (*      Dir_Count_Drives                                                *)
  36. (*      Dir_Convert_Time                                                *)
  37. (*      Dir_Convert_Date                                                *)
  38. (*      Dir_Find_First_File                                             *)
  39. (*      Dir_Find_Next_File                                              *)
  40. (*      Dir_Get_Free_Space                                              *)
  41. (*      Dir_Set_File_Date_And_Time                                      *)
  42. (*                                                                      *)
  43. (*----------------------------------------------------------------------*)
  44.  
  45. (*----------------------------------------------------------------------*)
  46. (*                  Map of MsDos Directory Entry                        *)
  47. (*----------------------------------------------------------------------*)
  48.  
  49. TYPE
  50.  
  51.    Directory_Record = RECORD
  52.                          Filler    : ARRAY[1..21] Of BYTE;
  53.                          File_Attr : BYTE;
  54.                          File_Time : INTEGER;
  55.                          File_Date : INTEGER;
  56.                          File_Size : ARRAY[1..2] Of INTEGER;
  57.                          File_Name : ARRAY[1..80] Of CHAR;
  58.                       END;
  59.  
  60. CONST
  61.    Dir_Attr_Read_Only    =  1;
  62.    Dir_Attr_Hidden       =  2;
  63.    Dir_Attr_System       =  4;
  64.    Dir_Attr_Volume_Label =  8;
  65.    Dir_Attr_Subdirectory = 16;
  66.    Dir_Attr_Archive      = 32;
  67.  
  68. (*----------------------------------------------------------------------*)
  69. (*   Convert_AsciiZ_To_String -- Convert Ascii Z string to Turbo String *)
  70. (*----------------------------------------------------------------------*)
  71.  
  72. PROCEDURE Convert_AsciiZ_To_String( VAR S: AnyStr );
  73.  
  74. (*----------------------------------------------------------------------*)
  75. (*                                                                      *)
  76. (*     Procedure:  Convert_AsciiZ_To_String                             *)
  77. (*                                                                      *)
  78. (*     Purpose:    Convert Ascii Z string to Turbo String               *)
  79. (*                                                                      *)
  80. (*     Calling Sequence:                                                *)
  81. (*                                                                      *)
  82. (*        Convert_AsciiZ_To_String( VAR S: AnyStr );                    *)
  83. (*                                                                      *)
  84. (*           S --- Ascii Z string to be turned into Turbo string        *)
  85. (*                                                                      *)
  86. (*     Calls:                                                           *)
  87. (*                                                                      *)
  88. (*        None                                                          *)
  89. (*                                                                      *)
  90. (*     Remarks:                                                         *)
  91. (*                                                                      *)
  92. (*        The string S is assumed to have already received the Ascii Z  *)
  93. (*        string in its [1]st thru [l]th locations.                     *)
  94. (*        This routine searches for the 0-character marking the end of  *)
  95. (*        the string and changes the Turbo string length (in S[0]) to   *)
  96. (*        reflect the actual string length.                             *)
  97. (*                                                                      *)
  98. (*----------------------------------------------------------------------*)
  99.  
  100. VAR
  101.    I: INTEGER;
  102.  
  103. BEGIN (* Convert_AsciiZ_To_String *)
  104.  
  105.    I := 1;
  106.    WHILE( S[I] <> CHR(0) ) DO I := I + 1;
  107.  
  108.    S[0] := CHR( I - 1 );
  109.  
  110. END   (* Convert_AsciiZ_To_String *);
  111.  
  112. (*----------------------------------------------------------------------*)
  113. (*   Convert_String_To_AsciiZ -- Convert Turbo string to Ascii Z String *)
  114. (*----------------------------------------------------------------------*)
  115.  
  116. PROCEDURE Convert_String_To_AsciiZ( VAR S: AnyStr );
  117.  
  118. (*----------------------------------------------------------------------*)
  119. (*                                                                      *)
  120. (*     Procedure:  Convert_String_To_AsciiZ                             *)
  121. (*                                                                      *)
  122. (*     Purpose:    Convert Turbo string to ascii Z string               *)
  123. (*                                                                      *)
  124. (*     Calling Sequence:                                                *)
  125. (*                                                                      *)
  126. (*        Convert_String_To_AsciiZ( VAR S: AnyStr );                    *)
  127. (*                                                                      *)
  128. (*           S --- Turbo string to be turned into Ascii Z string        *)
  129. (*                                                                      *)
  130. (*     Calls:                                                           *)
  131. (*                                                                      *)
  132. (*        None                                                          *)
  133. (*                                                                      *)
  134. (*----------------------------------------------------------------------*)
  135.  
  136. BEGIN (* Convert_String_To_AsciiZ *)
  137.  
  138.    S := S + CHR( 0 );
  139.  
  140. END   (* Convert_String_To_AsciiZ *);
  141.  
  142. (*----------------------------------------------------------------------*)
  143. (*     Dir_Get_Current_Path -- Get current directory path name          *)
  144. (*----------------------------------------------------------------------*)
  145.  
  146. FUNCTION Dir_Get_Current_Path( Drive         : CHAR;
  147.                                VAR Path_Name : AnyStr ) : INTEGER;
  148.  
  149. (*----------------------------------------------------------------------*)
  150. (*                                                                      *)
  151. (*     Function:   Dir_Get_Current_Path                                 *)
  152. (*                                                                      *)
  153. (*     Purpose:    Gets text of current directory path name             *)
  154. (*                                                                      *)
  155. (*     Calling Sequence:                                                *)
  156. (*                                                                      *)
  157. (*        Iok := Dir_Get_Current_Path( Drive : CHAR;                    *)
  158. (*                                     VAR Path_Name : AnyStr ) :       *)
  159. (*                                     INTEGER;                         *)
  160. (*                                                                      *)
  161. (*           Drive      --- Drive to look on                            *)
  162. (*           Path_Name  --- returned current path name                  *)
  163. (*                                                                      *)
  164. (*           Iok        --- 0 if all went well, else DOS return code    *)
  165. (*                                                                      *)
  166. (*     Calls:                                                           *)
  167. (*                                                                      *)
  168. (*        MsDos                                                         *)
  169. (*        Convert_String_To_AsciiZ                                      *)
  170. (*                                                                      *)
  171. (*----------------------------------------------------------------------*)
  172.  
  173. VAR
  174.    Dir_Reg: RegPack;
  175.  
  176. BEGIN (* Dir_Get_Current_Path *)
  177.  
  178.     Dir_Reg.Ah := $47;
  179.     Dir_Reg.Ds := SEG( Path_Name[1] );
  180.     Dir_Reg.Si := OFS( Path_Name[1] );
  181.     Dir_Reg.Dl := ORD( UpCase( Drive ) ) - ORD( '@' );
  182.  
  183.     MsDos( Dir_Reg );
  184.  
  185.     IF ( Carry_Flag AND Dir_Reg.Flags ) = 0 THEN
  186.        BEGIN
  187.           Dir_Get_Current_Path := 0;
  188.           Convert_AsciiZ_To_String( Path_Name );
  189.        END
  190.     ELSE
  191.        Dir_Get_Current_Path := Dir_Reg.Ax;
  192.  
  193. END   (* Dir_Get_Current_Path *);
  194.  
  195. (*----------------------------------------------------------------------*)
  196. (*     Dir_Set_Current_Path -- Set current directory path name          *)
  197. (*----------------------------------------------------------------------*)
  198.  
  199. FUNCTION Dir_Set_Current_Path( Path_Name : AnyStr ) : INTEGER;
  200.  
  201. (*----------------------------------------------------------------------*)
  202. (*                                                                      *)
  203. (*     Function:   Dir_Set_Current_Path                                 *)
  204. (*                                                                      *)
  205. (*     Purpose:    Sets new current directory path name                 *)
  206. (*                                                                      *)
  207. (*     Calling Sequence:                                                *)
  208. (*                                                                      *)
  209. (*        Iok := Dir_Set_Current_Path( Path_Name : AnyStr ) :           *)
  210. (*                                     INTEGER;                         *)
  211. (*                                                                      *)
  212. (*           Path_Name  --- New current path name                       *)
  213. (*                                                                      *)
  214. (*     Calls:                                                           *)
  215. (*                                                                      *)
  216. (*        MsDos                                                         *)
  217. (*        Convert_AsciiZ_To_String                                      *)
  218. (*                                                                      *)
  219. (*----------------------------------------------------------------------*)
  220.  
  221. VAR
  222.    Dir_Reg: RegPack;
  223.    I      : INTEGER;
  224.  
  225. BEGIN (* Dir_Set_Current_Path *)
  226.  
  227.    Convert_String_To_AsciiZ( Path_Name );
  228.  
  229.    Dir_Reg.Ah := $3B;
  230.    Dir_Reg.Ds := SEG( Path_Name[1] );
  231.    Dir_Reg.Dx := OFS( Path_Name[1] );
  232.  
  233.    MsDos( Dir_Reg );
  234.  
  235.    IF ( Carry_Flag AND Dir_Reg.Flags ) = 0 THEN
  236.       Dir_Set_Current_Path := 0
  237.    ELSE
  238.       Dir_Set_Current_Path := Dir_Reg.Ax;
  239.  
  240. END   (* Dir_Set_Current_Path *);
  241.  
  242.  
  243. (*----------------------------------------------------------------------*)
  244. (*     Dir_Set_Disk_Transfer_Address --- Set DMA address for disk I/O   *)
  245. (*----------------------------------------------------------------------*)
  246.  
  247. PROCEDURE Dir_Set_Disk_Transfer_Address( VAR DMA_Buffer );
  248.  
  249. (*----------------------------------------------------------------------*)
  250. (*                                                                      *)
  251. (*     Procedure:  Dir_Set_Disk_Transfer_Address                        *)
  252. (*                                                                      *)
  253. (*     Purpose:    Sets DMA address for disk transfers                  *)
  254. (*                                                                      *)
  255. (*     Calling Sequence:                                                *)
  256. (*                                                                      *)
  257. (*        Dir_Set_Disk_Transfer_Address( VAR DMA_Buffer );              *)
  258. (*                                                                      *)
  259. (*           DMA_Buffer --- direct memory access buffer                 *)
  260. (*                                                                      *)
  261. (*     Calls:                                                           *)
  262. (*                                                                      *)
  263. (*        MsDos                                                         *)
  264. (*                                                                      *)
  265. (*----------------------------------------------------------------------*)
  266.  
  267. VAR
  268.    Dir_Reg: RegPack;
  269.  
  270. BEGIN (* Dir_Set_Disk_Transfer_Address *)
  271.  
  272.    Dir_Reg.Ax := $1A00;
  273.    Dir_Reg.Ds := SEG( DMA_Buffer );
  274.    Dir_Reg.Dx := OFS( DMA_Buffer );
  275.  
  276.    MsDos( Dir_Reg );
  277.  
  278. END   (* Dir_Set_Disk_Transfer_Address *);
  279.  
  280. (*----------------------------------------------------------------------*)
  281. (*            Dir_Set_Default_Drive --- Set Default Drive               *)
  282. (*----------------------------------------------------------------------*)
  283.  
  284. PROCEDURE Dir_Set_Default_Drive( Drive: Char );
  285.  
  286. (*----------------------------------------------------------------------*)
  287. (*                                                                      *)
  288. (*     Procedure:  Dir_Set_Default_Drive                                *)
  289. (*                                                                      *)
  290. (*     Purpose:    Sets default drive for disk I/O                      *)
  291. (*                                                                      *)
  292. (*     Calling Sequence:                                                *)
  293. (*                                                                      *)
  294. (*        Dir_Set_Default_Drive( Drive : Char );                        *)
  295. (*                                                                      *)
  296. (*           Drive --- letter of default drive                          *)
  297. (*                                                                      *)
  298. (*     Calls:                                                           *)
  299. (*                                                                      *)
  300. (*        MsDos                                                         *)
  301. (*                                                                      *)
  302. (*----------------------------------------------------------------------*)
  303.  
  304. VAR
  305.    Dir_Reg: RegPack;
  306.  
  307. BEGIN  (* Dir_Set_Default_Drive *)
  308.  
  309.    Dir_Reg.Ah := $0E;
  310.    Dir_Reg.Dl := ORD( UpCase( Drive ) ) - ORD( 'A' );
  311.  
  312.    MsDos( Dir_Reg );
  313.  
  314. END   (* Dir_Set_Default_Drive *);
  315.  
  316.  
  317. (*----------------------------------------------------------------------*)
  318. (*            Dir_Get_Default_Drive --- Get Default Drive               *)
  319. (*----------------------------------------------------------------------*)
  320.  
  321. FUNCTION Dir_Get_Default_Drive: CHAR;
  322.  
  323. (*----------------------------------------------------------------------*)
  324. (*                                                                      *)
  325. (*     Function:  Dir_Get_Default_Drive                                 *)
  326. (*                                                                      *)
  327. (*     Purpose:   Gets default drive for disk I/O                       *)
  328. (*                                                                      *)
  329. (*     Calling Sequence:                                                *)
  330. (*                                                                      *)
  331. (*        Def_Drive := Dir_Get_Default_Drive : CHAR;                    *)
  332. (*                                                                      *)
  333. (*           Def_Drive --- Letter of default drive                      *)
  334. (*                                                                      *)
  335. (*     Calls:                                                           *)
  336. (*                                                                      *)
  337. (*        MsDos                                                         *)
  338. (*                                                                      *)
  339. (*----------------------------------------------------------------------*)
  340.  
  341. VAR
  342.    Dir_Reg: RegPack;
  343.  
  344. BEGIN  (* Dir_Get_Default_Drive *)
  345.  
  346.    Dir_Reg.Ah := $19;
  347.  
  348.    MsDos( Dir_Reg );
  349.  
  350.    Dir_Get_Default_Drive := CHR( Dir_Reg.Al + ORD( 'A' ) );
  351.  
  352. END   (* Dir_Get_Default_Drive *);
  353.  
  354. (*----------------------------------------------------------------------*)
  355. (*            Dir_Delete_File --- Delete A File                         *)
  356. (*----------------------------------------------------------------------*)
  357.  
  358. FUNCTION Dir_Delete_File( File_Name : AnyStr ) : INTEGER;
  359.  
  360. (*----------------------------------------------------------------------*)
  361. (*                                                                      *)
  362. (*     Function:  Dir_Delete_File                                       *)
  363. (*                                                                      *)
  364. (*     Purpose:   Deletes file in current directory                     *)
  365. (*                                                                      *)
  366. (*     Calling Sequence:                                                *)
  367. (*                                                                      *)
  368. (*        Ideleted := Dir_Delete_File( File_Name : AnyStr ): INTEGER;   *)
  369. (*                                                                      *)
  370. (*           File_Name --- name of file to delete                       *)
  371. (*           Ideleted  --- 0 if delete goes OK, else MSDOS return code  *)
  372. (*                                                                      *)
  373. (*     Calls:                                                           *)
  374. (*                                                                      *)
  375. (*        MsDos                                                         *)
  376. (*        Convert_String_To_AsciiZ                                      *)
  377. (*                                                                      *)
  378. (*----------------------------------------------------------------------*)
  379.  
  380. VAR
  381.    Dir_Reg: RegPack;
  382.  
  383. BEGIN  (* Dir_Delete_File *)
  384.  
  385.    Convert_String_To_AsciiZ( File_Name );
  386.  
  387.    Dir_Reg.Ah := $41;
  388.    Dir_Reg.Ds := SEG( File_Name[1] );
  389.    Dir_Reg.Dx := OFS( File_Name[1] );
  390.  
  391.    MsDos( Dir_Reg );
  392.  
  393.    IF ( Carry_Flag AND Dir_Reg.Flags ) = 0 THEN
  394.       Dir_Delete_File := 0
  395.    ELSE
  396.       Dir_Delete_File := Dir_Reg.Ax;
  397.  
  398. END   (* Dir_Delete_File *);
  399.  
  400. (*----------------------------------------------------------------------*)
  401. (*            Dir_Count_Drives --- Count number of drives in system     *)
  402. (*----------------------------------------------------------------------*)
  403.  
  404. FUNCTION Dir_Count_Drives : INTEGER;
  405.  
  406. (*----------------------------------------------------------------------*)
  407. (*                                                                      *)
  408. (*     Function:  Dir_Count_Drives                                      *)
  409. (*                                                                      *)
  410. (*     Purpose:   Finds number of installed DOS drives                  *)
  411. (*                                                                      *)
  412. (*     Calling Sequence:                                                *)
  413. (*                                                                      *)
  414. (*        ndrives := Dir_Count_Drives : INTEGER;                        *)
  415. (*                                                                      *)
  416. (*           ndrives --- number of drives in system                     *)
  417. (*                                                                      *)
  418. (*     Calls:                                                           *)
  419. (*                                                                      *)
  420. (*        MsDos                                                         *)
  421. (*                                                                      *)
  422. (*----------------------------------------------------------------------*)
  423.  
  424. VAR
  425.    Dir_Reg: RegPack;
  426.  
  427. BEGIN  (* Dir_Count_Drives *)
  428.  
  429.    Dir_Reg.Ah := $19;
  430.  
  431.    MsDos( Dir_Reg );
  432.  
  433.    Dir_Reg.Ah := $0E;
  434.    Dir_Reg.Dl := Dir_Reg.Al;
  435.  
  436.    MsDos( Dir_Reg );
  437.  
  438.    Dir_Count_Drives := Dir_Reg.Al;
  439.  
  440. END   (* Dir_Count_Drives *);
  441.  
  442.  
  443. (*----------------------------------------------------------------------*)
  444. (*            Dir_Convert_Time --- Convert directory creation time      *)
  445. (*----------------------------------------------------------------------*)
  446.  
  447. PROCEDURE Dir_Convert_Time ( Time : INTEGER; VAR S_Time : AnyStr );
  448.  
  449. (*----------------------------------------------------------------------*)
  450. (*                                                                      *)
  451. (*     Procedure: Dir_Convert_Time                                      *)
  452. (*                                                                      *)
  453. (*     Purpose:   Convert creation time from directory to characters.   *)
  454. (*                                                                      *)
  455. (*     Calling Sequence:                                                *)
  456. (*                                                                      *)
  457. (*        Dir_Convert_Time( Time       : INTEGER;                       *)
  458. (*                          VAR S_Time : AnyStr ) : INTEGER;            *)
  459. (*                                                                      *)
  460. (*           Time   --- time as read from directory                     *)
  461. (*           S_Time --- converted time in hh:mm:ss                      *)
  462. (*                                                                      *)
  463. (*     Calls:                                                           *)
  464. (*                                                                      *)
  465. (*        STR                                                           *)
  466. (*                                                                      *)
  467. (*----------------------------------------------------------------------*)
  468.  
  469. VAR
  470.    HH : String[2];
  471.    MM : String[2];
  472.    SS : String[2];
  473.  
  474. BEGIN (* Dir_Convert_Time *)
  475.  
  476.    STR( ( Time SHR 11 ):2 , HH );
  477.    IF HH[1] = ' ' THEN HH[1] := '0';
  478.  
  479.    STR( ( ( Time AND $07E0 ) SHR 5 ):2 , MM );
  480.    IF MM[1] = ' ' THEN MM[1] := '0';
  481.  
  482.    STR( ( ( Time AND $001F ) * 2 ):2 , SS );
  483.    IF SS[1] = ' ' THEN SS[1] := '0';
  484.  
  485.    S_Time := HH + ':' + MM + ':' + SS;
  486.  
  487. END  (* Dir_Convert_Time *);
  488.  
  489. (*----------------------------------------------------------------------*)
  490. (*            Dir_Convert_Date --- Convert directory creation date      *)
  491. (*----------------------------------------------------------------------*)
  492.  
  493. PROCEDURE Dir_Convert_Date ( Date : INTEGER; VAR S_Date : AnyStr );
  494.  
  495. (*----------------------------------------------------------------------*)
  496. (*                                                                      *)
  497. (*     Procedure: Dir_Convert_Date                                      *)
  498. (*                                                                      *)
  499. (*     Purpose:   Convert creation date from directory to characters.   *)
  500. (*                                                                      *)
  501. (*     Calling Sequence:                                                *)
  502. (*                                                                      *)
  503. (*        Dir_Convert_Date( Date       : INTEGER;                       *)
  504. (*                          VAR S_Date : AnyStr ) : INTEGER;            *)
  505. (*                                                                      *)
  506. (*           Date   --- date as read from directory                     *)
  507. (*           S_Date --- converted date in yy/mm/dd                      *)
  508. (*                                                                      *)
  509. (*     Calls:                                                           *)
  510. (*                                                                      *)
  511. (*        STR                                                           *)
  512. (*                                                                      *)
  513. (*----------------------------------------------------------------------*)
  514.  
  515. VAR
  516.    YY : String[2];
  517.    MM : String[2];
  518.    DD : String[2];
  519.  
  520. BEGIN (* Dir_Convert_Date *)
  521.  
  522.    STR( ( 80 + ( Date SHR 9 ) ) : 2 , YY );
  523.  
  524.    STR( ( ( Date AND $01E0 ) SHR 5 ):2 , MM );
  525.    IF MM[1] = ' ' THEN MM[1] := '0';
  526.  
  527.    STR( ( Date AND $001F ):2 , DD );
  528.    IF DD[1] = ' ' THEN DD[1] := '0';
  529.  
  530.    S_Date := YY + '/' + MM + '/' + DD;
  531.  
  532. END  (* Dir_Convert_Date *);
  533.  
  534. (*----------------------------------------------------------------------*)
  535. (*   Dir_Find_First_File --- Find First File Matching Given Specs       *)
  536. (*----------------------------------------------------------------------*)
  537.  
  538. FUNCTION Dir_Find_First_File(     File_Pattern: AnyStr;
  539.                               VAR First_File  : Directory_Record  ):
  540.                               INTEGER;
  541.  
  542. (*----------------------------------------------------------------------*)
  543. (*                                                                      *)
  544. (*     Function:   Dir_Find_First_File                                  *)
  545. (*                                                                      *)
  546. (*     Purpose:    Find first file in directory matching specs          *)
  547. (*                                                                      *)
  548. (*     Calling Sequence:                                                *)
  549. (*                                                                      *)
  550. (*        Iok := Dir_Find_First_File(     File_Pattern: AnyStr;         *)
  551. (*                                    VAR First_File  :                 *)
  552. (*                                        Directory_Record ): INTEGER;  *)
  553. (*                                                                      *)
  554. (*           File_Pattern --- File pattern to look for.                 *)
  555. (*           First_File   --- First file matching specs.                *)
  556. (*           Iok          --- 0 if file found, else MsDos return code.  *)
  557. (*                                                                      *)
  558. (*     Calls:                                                           *)
  559. (*                                                                      *)
  560. (*        Dir_Set_Disk_Transfer_Address                                 *)
  561. (*        MsDos                                                         *)
  562. (*                                                                      *)
  563. (*     Remarks:                                                         *)
  564. (*                                                                      *)
  565. (*        The file pattern can be any standard MSDOS file pattern,      *)
  566. (*        including wildcards.  For a complete directory list, enter    *)
  567. (*        '*.*' as the pattern.   Use routine 'Dir_Find_Next_File'      *)
  568. (*        to get the remaining files.                                   *)
  569. (*                                                                      *)
  570. (*----------------------------------------------------------------------*)
  571.  
  572. VAR
  573.    Dir_Reg: RegPack;
  574.  
  575. BEGIN (* Find_First_File *)
  576.  
  577.    Dir_Set_Disk_Transfer_Address( First_File );
  578.  
  579.    Convert_String_To_AsciiZ( File_Pattern );
  580.  
  581.    Dir_Reg.Ds := SEG( File_Pattern[1] );
  582.    Dir_Reg.Dx := OFS( File_Pattern[1] );
  583.    Dir_Reg.Ax := $4E00;
  584.    Dir_Reg.Cx := $FF;
  585.  
  586.    MsDos( Dir_Reg );
  587.  
  588.    IF ( Carry_Flag AND Dir_Reg.Flags ) = 0 THEN
  589.       Dir_Find_First_File := 0
  590.    ELSE
  591.       Dir_Find_First_File := Dir_Reg.Ax;
  592.  
  593. END   (* Find_First_File *);
  594.  
  595.  
  596. (*----------------------------------------------------------------------*)
  597. (*     Dir_Find_Next_File  --- Find Next File Matching Given Specs      *)
  598. (*----------------------------------------------------------------------*)
  599.  
  600. FUNCTION Dir_Find_Next_File ( VAR Next_File : Directory_Record ) : INTEGER;
  601.  
  602. (*----------------------------------------------------------------------*)
  603. (*                                                                      *)
  604. (*     Function:   Dir_Find_Next_File                                   *)
  605. (*                                                                      *)
  606. (*     Purpose:    Finds next file in directory matching specs          *)
  607. (*                                                                      *)
  608. (*     Calling Sequence:                                                *)
  609. (*                                                                      *)
  610. (*        Iok := Dir_Find_Next_File ( VAR Next_File :                   *)
  611. (*                                        Directory_Record ) : INTEGER; *)
  612. (*                                                                      *)
  613. (*           Next_File    --- Next file matching specs.                 *)
  614. (*           Iok          --- Returned as 0 if file found, else MsDos   *)
  615. (*                            return code indicating error.             *)
  616. (*                                                                      *)
  617. (*     Calls:                                                           *)
  618. (*                                                                      *)
  619. (*        MsDos                                                         *)
  620. (*        Dir_Set_Disk_Transfer_Address                                 *)
  621. (*                                                                      *)
  622. (*----------------------------------------------------------------------*)
  623.  
  624. VAR
  625.    Dir_Reg : RegPack;
  626.  
  627. BEGIN (* Find_Next_File  *)
  628.  
  629.    Dir_Set_Disk_Transfer_Address( Next_File );
  630.  
  631.    Dir_Reg.Ax := $4F00;
  632.  
  633.    MsDos( Dir_Reg );
  634.  
  635.    IF ( Carry_Flag AND Dir_Reg.Flags ) = 0 THEN
  636.       Dir_Find_Next_File := 0
  637.    ELSE
  638.       Dir_Find_Next_File := Dir_Reg.Ax;
  639.  
  640. END   (* Find_Next_File  *);
  641.  
  642. (*----------------------------------------------------------------------*)
  643. (*     Dir_Get_Free_Space  --- Find Next File Matching Given Specs      *)
  644. (*----------------------------------------------------------------------*)
  645.  
  646. FUNCTION Dir_Get_Free_Space ( Drive : CHAR ) : REAL;
  647.  
  648. (*----------------------------------------------------------------------*)
  649. (*                                                                      *)
  650. (*     Function:   Dir_Get_Free_Space                                   *)
  651. (*                                                                      *)
  652. (*     Purpose:    Gets amount of available space on a drive            *)
  653. (*                                                                      *)
  654. (*     Calling Sequence:                                                *)
  655. (*                                                                      *)
  656. (*        FSpace := Dir_Get_Free_Space ( Drive : CHAR ) : REAL;         *)
  657. (*                                                                      *)
  658. (*           Drive        --- Drive letter for which to get free space  *)
  659. (*           Fspace       --- Returned number of bytes of free space    *)
  660. (*                                                                      *)
  661. (*     Calls:                                                           *)
  662. (*                                                                      *)
  663. (*        MsDos                                                         *)
  664. (*                                                                      *)
  665. (*     Remarks:                                                         *)
  666. (*                                                                      *)
  667. (*         If the free space can't be found, -1 is returned.            *)
  668. (*         This is most likely to happen if an unformatted or wrongly   *)
  669. (*         formatted disk is to be checked.                             *)
  670. (*                                                                      *)
  671. (*----------------------------------------------------------------------*)
  672.  
  673. VAR
  674.    Dir_Reg  : RegPack;
  675.    Clusters : REAL;
  676.    Sectors  : REAL;
  677.    Bytes    : REAL;
  678.  
  679. BEGIN (* Dir_Get_Free_Space  *)
  680.  
  681.                                    (* Request drive information *)
  682.  
  683.    Dir_Reg.DL := ORD(UpCase( Drive )) - ORD('A') + 1;
  684.    Dir_Reg.AH := $36;
  685.  
  686.    MsDos( Dir_Reg );
  687.  
  688.                                    (* Compute free space *)
  689.  
  690.    WITH Dir_Reg DO
  691.       BEGIN
  692.  
  693.          Sectors  := AX;
  694.          Clusters := BX;
  695.          Bytes    := CX;
  696.  
  697.          IF AX = $FFFF THEN
  698.             Dir_Get_Free_Space := -1.0
  699.          ELSE
  700.             Dir_Get_Free_Space := Clusters * Bytes * Sectors;
  701.  
  702.       END;
  703.  
  704. END   (* Dir_Get_Free_Space  *);
  705.  
  706. (*----------------------------------------------------------------------*)
  707. (*     Dir_Set_File_Date_And_Time -- Set file date and time stamp       *)
  708. (*----------------------------------------------------------------------*)
  709.  
  710. FUNCTION Dir_Set_File_Date_And_Time( File_Handle: INTEGER;
  711.                                      File_Date  : INTEGER;
  712.                                      File_Time  : INTEGER  ) : INTEGER;
  713.  
  714. (*----------------------------------------------------------------------*)
  715. (*                                                                      *)
  716. (*     Function:   Dir_Set_File_Date_And_Time                           *)
  717. (*                                                                      *)
  718. (*     Purpose:    Sets file time and date stamp                        *)
  719. (*                                                                      *)
  720. (*     Calling Sequence:                                                *)
  721. (*                                                                      *)
  722. (*        Error := Dir_Set_File_Date_And_Time( File_Handle: INTEGER;    *)
  723. (*                                             File_Date  : INTEGER;    *)
  724. (*                                             File_Time  : INTEGER ):  *)
  725. (*                                             INTEGER;                 *)
  726. (*                                                                      *)
  727. (*           File_Handle --- File handle of file to set time/date on    *)
  728. (*           File_Date   --- File date in packed DOS form               *)
  729. (*           File_Time   --- File time in packed DOS form               *)
  730. (*           Error       --- DOS error return code                      *)
  731. (*                                                                      *)
  732. (*     Calls:                                                           *)
  733. (*                                                                      *)
  734. (*        MsDos                                                         *)
  735. (*                                                                      *)
  736. (*----------------------------------------------------------------------*)
  737.  
  738. VAR
  739.    Dir_Reg  : RegPack;
  740.  
  741. BEGIN (* Dir_Set_File_Date_And_Time *)
  742.  
  743.                                    (* Set up parameters to DOS call *)
  744.    WITH Dir_Reg DO
  745.       BEGIN
  746.          Cx := File_Time;
  747.          Dx := File_Date;
  748.          Bx := File_Handle;
  749.          Ah := $57;
  750.          Al := 1;
  751.       END;
  752.                                    (* Set date and time *)
  753.    MsDos( Dir_Reg );
  754.                                    (* Check for bad return  *)
  755.  
  756.    IF ( Carry_Flag AND Dir_Reg.Flags ) = 0 THEN
  757.       Dir_Set_File_Date_And_Time := 0
  758.    ELSE
  759.       Dir_Set_File_Date_And_Time := Dir_Reg.Ax;
  760.  
  761. END   (* Dir_Set_File_Date_And_Time *);
  762.  
  763. (*----------------------------------------------------------------------*)
  764. (*     Dir_Get_File_Date_And_Time -- Get file date and time stamp       *)
  765. (*----------------------------------------------------------------------*)
  766.  
  767. FUNCTION Dir_Get_File_Date_And_Time(     File_Handle: INTEGER;
  768.                                      VAR File_Date  : INTEGER;
  769.                                      VAR File_Time  : INTEGER  ) : INTEGER;
  770.  
  771. (*----------------------------------------------------------------------*)
  772. (*                                                                      *)
  773. (*     Function:   Dir_Get_File_Date_And_Time                           *)
  774. (*                                                                      *)
  775. (*     Purpose:    Gets file time and date stamp                        *)
  776. (*                                                                      *)
  777. (*     Calling Sequence:                                                *)
  778. (*                                                                      *)
  779. (*        Error := Dir_Get_File_Date_And_Time(     File_Handle: INTEGER;*)
  780. (*                                             VAR File_Date  : INTEGER;*)
  781. (*                                                 File_Time  : INTEGER *)
  782. (*                                           ): INTEGER;                *)
  783. (*                                                                      *)
  784. (*           File_Handle --- File handle of file to set time/date on    *)
  785. (*           File_Date   --- File date in packed DOS form               *)
  786. (*           File_Time   --- File time in packed DOS form               *)
  787. (*           Error       --- DOS error return code                      *)
  788. (*                                                                      *)
  789. (*     Calls:                                                           *)
  790. (*                                                                      *)
  791. (*        MsDos                                                         *)
  792. (*                                                                      *)
  793. (*----------------------------------------------------------------------*)
  794.  
  795. VAR
  796.    Dir_Reg  : RegPack;
  797.  
  798. BEGIN (* Dir_Get_File_Date_And_Time *)
  799.  
  800.                                    (* Set up parameters to DOS call *)
  801.    WITH Dir_Reg DO
  802.       BEGIN
  803.          Bx := File_Handle;
  804.          Ah := $57;
  805.          Al := 0;
  806.       END;
  807.                                    (* Get date and time *)
  808.    MsDos( Dir_Reg );
  809.                                    (* Check for bad return  *)
  810.  
  811.    IF ( Carry_Flag AND Dir_Reg.Flags ) = 0 THEN
  812.       BEGIN
  813.          Dir_Get_File_Date_And_Time := 0;
  814.          File_Time                  := Dir_Reg.Cx;
  815.          File_Date                  := Dir_Reg.Dx;
  816.       END
  817.    ELSE
  818.       BEGIN
  819.          Dir_Get_File_Date_And_Time := Dir_Reg.Ax;
  820.          File_Time                  := 0;
  821.          File_Date                  := 0;
  822.       END;
  823.  
  824. END   (* Dir_Get_File_Date_And_Time *);
  825.  
  826.  
  827.